package com.edgarli.web.controller.detail;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.edgarli.common.annotation.Log;
import com.edgarli.common.core.controller.BaseController;
import com.edgarli.common.core.domain.AjaxResult;
import com.edgarli.common.enums.BusinessType;
import com.edgarli.detail.domain.TExpenditure;
import com.edgarli.detail.service.ITExpenditureService;
import com.edgarli.common.utils.poi.ExcelUtil;
import com.edgarli.common.core.page.TableDataInfo;

/**
 * 家庭支出Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/detail/expenditure")
public class TExpenditureController extends BaseController
{
    @Autowired
    private ITExpenditureService tExpenditureService;

    /**
     * 查询家庭支出列表
     */
    @PreAuthorize("@ss.hasPermi('detail:expenditure:list')")
    @GetMapping("/list")
    public TableDataInfo list(TExpenditure tExpenditure)
    {
        startPage();
        List<TExpenditure> list = tExpenditureService.selectTExpenditureList(tExpenditure);
        return getDataTable(list);
    }

    /**
     * 导出家庭支出列表
     */
    @PreAuthorize("@ss.hasPermi('detail:expenditure:export')")
    @Log(title = "家庭支出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TExpenditure tExpenditure)
    {
        List<TExpenditure> list = tExpenditureService.selectTExpenditureList(tExpenditure);
        ExcelUtil<TExpenditure> util = new ExcelUtil<TExpenditure>(TExpenditure.class);
        util.exportExcel(response, list, "家庭支出数据");
    }

    /**
     * 获取家庭支出详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:expenditure:query')")
    @GetMapping(value = "/{expenditureId}")
    public AjaxResult getInfo(@PathVariable("expenditureId") Long expenditureId)
    {
        return AjaxResult.success(tExpenditureService.selectTExpenditureByExpenditureId(expenditureId));
    }

    /**
     * 新增家庭支出
     */
    @PreAuthorize("@ss.hasPermi('detail:expenditure:add')")
    @Log(title = "家庭支出", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TExpenditure tExpenditure)
    {
        return toAjax(tExpenditureService.saveOrUpdate(tExpenditure));
    }

    /**
     * 修改家庭支出
     */
    @PreAuthorize("@ss.hasPermi('detail:expenditure:edit')")
    @Log(title = "家庭支出", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TExpenditure tExpenditure)
    {
        return toAjax(tExpenditureService.saveOrUpdate(tExpenditure));
    }

    /**
     * 删除家庭支出
     */
    @PreAuthorize("@ss.hasPermi('detail:expenditure:remove')")
    @Log(title = "家庭支出", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expenditureIds}")
    public AjaxResult remove(@PathVariable Long[] expenditureIds)
    {
        return toAjax(tExpenditureService.deleteTExpenditureByExpenditureIds(expenditureIds));
    }
}
